fix: add explicit timeout to OpenAPI tool httpx client#4432
fix: add explicit timeout to OpenAPI tool httpx client#4432fuki01 wants to merge 3 commits intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @fuki01, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where OpenAPI tool HTTP requests were failing due to an unexpected timeout. The underlying HTTP client library, Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Response from ADK Triaging Agent Hello @fuki01, thank you for creating this PR! Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). In addition, could you please provide a testing plan and logs or screenshot after the fix is applied? This information will help reviewers to review your PR more efficiently. Thanks! |
There was a problem hiding this comment.
Code Review
This pull request addresses a httpx.ReadTimeout issue by setting an explicit timeout=None for the httpx.AsyncClient, restoring the previous behavior of the requests library. While this fixes the immediate problem, I have a significant concern about disabling timeouts altogether, as it can lead to service instability. I've added a high-severity comment recommending the use of a large default timeout as a safety measure instead of completely disabling it.
| async with httpx.AsyncClient( | ||
| verify=request_params.pop("verify", True) | ||
| verify=request_params.pop("verify", True), | ||
| timeout=None, |
There was a problem hiding this comment.
While setting timeout=None restores the previous behavior of requests and fixes the immediate httpx.ReadTimeout issue, it introduces a significant risk. Disabling timeouts can cause requests to hang indefinitely if the remote API is unresponsive, potentially leading to resource exhaustion and service instability.
Even though a follow-up is mentioned in the pull request description, I strongly recommend addressing this now by setting a generous default timeout (e.g., 10 minutes) instead of None. This would provide a crucial safety net. A truly indefinite timeout should be an explicit choice by the user of the tool, not the default behavior.
The migration from `requests` to `httpx.AsyncClient` in PR google#2872 did not specify a timeout parameter. Since `requests` defaults to no timeout while `httpx` defaults to 5 seconds, this causes `ReadTimeout` errors for API calls that take longer than 5 seconds. Set timeout to `None` to restore the previous behavior. Closes google#4431
415aa5a to
69d0179
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request addresses an httpx.ReadTimeout issue by setting an explicit timeout for the httpx.AsyncClient. The change restores the previous behavior of the requests library, which had no timeout by default. My review includes a suggestion to make the timeout handling more robust and configurable. While the current fix works, disabling timeouts completely can be risky. The suggestion aims to improve the design for future enhancements without changing the immediate behavior of this fix.
| async with httpx.AsyncClient( | ||
| verify=request_params.pop("verify", True) | ||
| verify=request_params.pop("verify", True), | ||
| timeout=None, |
There was a problem hiding this comment.
While setting timeout=None restores the previous behavior of requests, it's risky to have no timeout as requests can hang indefinitely, potentially leading to resource exhaustion.
To make this more robust and prepare for a future change where the timeout is configurable (as mentioned in the PR description), I suggest reading the timeout from request_params. This way, RestApiTool can be updated to control the timeout value without needing to change this helper function again.
Using request_params.pop("timeout", None) will keep the current behavior of no timeout by default if no other changes are made, but makes the function extensible for a proper fix.
| timeout=None, | |
| timeout=request_params.pop("timeout", None), |
There was a problem hiding this comment.
can you please address this.
There was a problem hiding this comment.
I've updated the implementation based on the feedback:
- Changed to
request_params.pop("timeout", httpx.Timeout(600.0))— this makes the timeout configurable viarequest_params, soRestApiToolcan control timeout without modifying_request()in the future. - Instead of
None(no timeout), I set a generous 10-minute default as a safety net to prevent indefinite hangs while still accommodating slow API responses.
|
Hi @fuki01, Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please address the suggestion. |
Use request_params.pop("timeout", None) instead of hardcoded None,
allowing RestApiTool to control timeout without modifying _request().
Set a generous 600s default to prevent indefinite hangs while still accommodating slow API responses.
fad2e4e to
d12bdc2
Compare
Summary
requeststohttpx.AsyncClient, but did not specify a timeoutrequestsdefaults to no timeout, whilehttpxdefaults to 5 secondshttpx.ReadTimeoutfor API calls taking longer than 5 secondsThis PR sets
timeout=Noneto restore the previousrequestsbehavior as a minimal fix.Note:
None(no timeout) matches the previous behavior, but the team may want to choose a more appropriate default value in a follow-up.Closes #4431